<?php

namespace app\api\logic\page;

use think\facade\Request;
use app\common\repository\user\R as userRRepository;
use app\common\repository\articleTag\R as ArticleTagRRepository;

class Search
{
    public function __construct(
        UserRRepository $userRRepository,
        ArticleTagRRepository $articleTagRRepository
    )
    {
        $this->userRRepository = $userRRepository;
        $this->articleTagRRepository = $articleTagRRepository;
    }

    public function info()
    {
        $tagId = Request::param('tagId');
        $keyword = Request::param('keyword');
        $tag = [];
        $author = [];
        if (!$tagId && !$keyword) {
            return ['done' => false, 'code' => config('code.common.paramsRequire')];
        }
        if (!empty($tagId)) {
            $tag =  $this->articleTagRRepository->getTag(['id' => $tagId]);
        }
        if (!empty($keyword)) {
            $author =  $this->userRRepository->getUsers(['nickname', 'like', '%' . $keyword . '%']);
        }
        return ['data' => ['tag' => $tag, 'author' => $author]];
    }
}
